import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/back_button_widget.dart';

/// 支付成功页面
class PaySuccessPage extends StatefulWidget {
  const PaySuccessPage({super.key});

  @override
  State<PaySuccessPage> createState() => _PaySuccessPageState();
}

class _PaySuccessPageState extends State<PaySuccessPage> {
  late BuildContext _context;

  late Color _showColor;

  @override
  void initState() {
    super.initState();

    // _showColor = colorGrey5;
    _showColor = colorGreen2;
  }

  @override
  Widget build(BuildContext context) {

    _context = context;
    return Scaffold(
      backgroundColor: colorWhite2,
      body: Stack(
        children: [
          Positioned(
            top: 0,
            child: _background(),
          ),
          Positioned.fill(child: _content()),
        ],
      ),
    );
  }

  /// 背景显示
  _background() {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: 474,
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [colorBlue22, colorBlue23],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
        ),
      ),
    );
  }

  /// 内容显示
  _content() {
    double top = MediaQuery.of(_context).padding.top;
    return Padding(
      padding: EdgeInsets.only(top: top),
      child: Column(
        children: [
          _titleItem(),
          hiSpace(height: 100),
          _iconItem(),
          hiSpace(height: 80),
          _sucItem(),
        ],
      ),
    );
  }

  /// 标题组件
  _titleItem() {
    return SizedBox(
      height: 88,
      child: Row(
        children: [
          Padding(
            padding: EdgeInsets.only(left: 10),
            child: BackButtonWidget.close(
              pageContext: _context,
              onTapFun: _onTapFunGb,
            ),
          ),
        ],
      ),
    );
  }

  /// 完成显示
  _sucItem() {
    return SizedBox(
      height: 120,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "支付完成",
            style: TextStyle(
              fontSize: 60,
              fontWeight: FontWeight.w500,
              color: _showColor,
            ),
          )
        ],
      ),
    );
  }

  /// 图标
  _iconItem() {
    return Container(
      width: 160,
      height: 160,
      decoration: BoxDecoration(
        color: colorWhite1,
        borderRadius: BorderRadius.circular(80),
        border: Border.all(color: _showColor, width: 6),
      ),
      child: Center(
        child: SvgPicture.asset(
          "images/package/show_label_1.svg",
          width: 80,
          height: 80,
          color: _showColor,
        ),
      ),
    );
  }

  /// 关闭按钮点击方法
  void _onTapFunGb() {
    // 跳转到购买页面

    Navigator.pushNamedAndRemoveUntil(_context, "/tab", (route) => false);

  }
}
